// user/order/against.js
var home = require("../../utils/util.js");
var url = home.home;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    price:600,//商品价格
    money:570,//合计
    discount:8.5,//折扣
    does:30,//优惠券
    does_money:0,//优惠金额
    goodsData:{},
    commodityListJsonStr:[],
    bgcolor: home.getKey('bgcolor'),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let goodsData = JSON.parse(decodeURIComponent(options.goodsData));
    let commodityListJsonStr = JSON.parse(goodsData.commodityListJsonStr);
    for (let i = 0; i < commodityListJsonStr.length; i++) {
      if (commodityListJsonStr[i].pic) {
        let pic = commodityListJsonStr[i].pic.split(',');
        commodityListJsonStr[i].pic = 'https://kyz.fbhkj.com//' + pic[0];
      }
    }
    this.setData({
      goodsData:goodsData,
      commodityListJsonStr:commodityListJsonStr
    })
  },

  //订单详情
  getOrderInfo(){
    let that = this;
    let goodsData = this.data.goodsData;
    wx.request({
      url: url + 'app/order/detail?orderId='+goodsData.id,
      data:{
        orderId:goodsData.id,
      },
      method: 'GET',
      header: {
        "content-type": "application/json", // 默认
      },
      success:function (res) {
        if (res.data.code == 200) {
          let couponTitle = '';
          for (let i = 0; i < res.data.result.couponListJson.length; i++) {
            if (i == res.data.result.couponListJson.length - 1) {
              couponTitle += res.data.result.couponListJson[i].ticketName;
            } else {
              couponTitle += res.data.result.couponListJson[i].ticketName + ',';
            }
          }
          res.data.result.couponTitle = couponTitle;
          that.setData({
            goodsData:res.data.result
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getOrderInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})